//package com.bajiao.admin.task;
//
//import com.bajiao.common.util.RedisUtil;
//import com.bajiao.entity.account.Account;
//import com.bajiao.entity.account.AccountBill;
//import com.bajiao.entity.user.User;
//import com.bajiao.service.account.AccountBillService;
//import com.bajiao.service.account.AccountService;
//import com.bajiao.service.user.UserService;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//import java.util.List;
//
//@Component
//@EnableScheduling
//@Slf4j
//public class ScheduleTest {
//
//    @Resource
//    private UserService userService;
//
//    @Resource
//    private RedisUtil redisUtil;
//
//    @Resource
//    private AccountService accountService;
//
//    @Resource
//    private AccountBillService accountBillService;
//
//    /**
//     * 第一次等待10秒，之后每15秒钟执行一次
//     */
//    @Scheduled(fixedRate = 15000)
//    public void test1() {
//        log.info("###################{}","开始执行定时任务.");
//        List<User> userList = userService.list(new QueryWrapper<User>().lambda().isNotNull(User::getSuperId));
//
//
//        if(userList != null && userList.size() > 0) {
//            for (User user : userList) {
//
//                // 是否奖励+用户ID+用户上级ID
////                redisUtil.set("isAward:userId:superUserId:", "0:" + user.getId() +":" + user.getSuperId());
//                // 操作账户美豆余额
//                Account account = accountService.queryByUserId(user.getId());
//                BigDecimal beforeMoney = account.getMoney();
//                BigDecimal afterMoney = account.getMoney().add(new BigDecimal(5));
//                BigDecimal changeMoney = new BigDecimal(5);
//                account.setMoney(afterMoney); // 增加5美豆
//                accountService.updateById(account);
//
//                // 操作账户流水
//                AccountBill bill = new AccountBill();
//                bill.setUserId(user.getId());
//                bill.setBeforeMoney(beforeMoney);
//                bill.setAfterMoney(afterMoney);
//                bill.setChangeMoney(changeMoney);
//                bill.setSign("+");
//                bill.setBillType(1);
//                bill.setType(99);
//                bill.setTitle("邀请奖励");
//                accountBillService.save(bill);
//                redisUtil.del("isAward:userId:superUserId:0" + user.getId() +":" + user.getSuperId());
//            }
//        }
//    }
//
//}
